package cn.ddiancan.xddcloud.sentinel.config;

import cn.ddiancan.xddcloud.sentinel.cleaner.XddcloudUrlCleaner;
import cn.ddiancan.xddcloud.sentinel.feign.XddcloudSentinelFeign;
import cn.ddiancan.xddcloud.sentinel.handle.XddcloudRequestBlockHandler;
import cn.ddiancan.xddcloud.sentinel.parser.XddcloudRequestOriginParser;
import com.alibaba.csp.sentinel.adapter.spring.webmvc_v6x.callback.BlockExceptionHandler;
import com.alibaba.csp.sentinel.adapter.spring.webmvc_v6x.callback.RequestOriginParser;
import com.alibaba.csp.sentinel.adapter.web.common.UrlCleaner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(name = "feign.sentinel.enabled")
public class XddcloudSentinelConfiguration {

    @Bean
    public XddcloudSentinelFeign.Builder xddcloudSentinelFeign() {
        return XddcloudSentinelFeign.builder();
    }

    @Bean
    public BlockExceptionHandler blockExceptionHandler() {
        return new XddcloudRequestBlockHandler();
    }

    @Bean
    public RequestOriginParser requestOriginParser() {
        return new XddcloudRequestOriginParser();
    }

    @Bean
    public UrlCleaner xddcloudUrlCleaner() {
        return new XddcloudUrlCleaner();
    }

}
